package com.yztc.ui.home.adapter;

import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import java.util.List;

/**
 * Created by My on 2016/10/10.
 */
public class DetailsPagerAdapter extends PagerAdapter {
    private List<ImageView> mImageViews;
    public DetailsPagerAdapter(List<ImageView> mImageViews){
        this.mImageViews = mImageViews;
    }

    public void setImageViews(List<ImageView> mImageViews){
        this.mImageViews = mImageViews;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return Integer.MAX_VALUE;
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        container.addView(mImageViews.get(position%mImageViews.size()));
        return mImageViews.get(position%mImageViews.size());
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        mImageViews.get(position%mImageViews.size()).clearFocus();
        container.removeView(mImageViews.get(position%mImageViews.size()));
    }

    @Override public int getItemPosition(Object object) { return POSITION_NONE; }

}
